﻿
namespace CsvSegítő.typeconverter
{
    using System;
    using System.Globalization;
    public class NullableSByteConverter : NullableConverter<sbyte?>
    {
        private readonly SByteConverter sbyteConverter;
        private readonly NumberStyles numberStyles;

        public NullableSByteConverter()
            : this(CultureInfo.InvariantCulture)
        {
        }

        public NullableSByteConverter(IFormatProvider formatProvider)
            : this(formatProvider, NumberStyles.None)
        {
        }

        public NullableSByteConverter(IFormatProvider formatProvider, NumberStyles numberStyles)
        {
            sbyteConverter = new SByteConverter(formatProvider, numberStyles);
        }

        protected override bool InternalConvert(string value, out sbyte? result)
        {
            result = default(sbyte?);

            sbyte innerConverterResult;
            if (sbyteConverter.TryConvert(value, out innerConverterResult))
            {
                result = innerConverterResult;

                return true;
            }
            return false;
        }
    }
}